package com.smart.web.controller.system;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.smart.common.core.domain.R;
import com.smart.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.smart.common.annotation.Log;
import com.smart.common.core.controller.BaseController;
import com.smart.common.core.domain.AjaxResult;
import com.smart.common.enums.BusinessType;
import com.smart.system.domain.WorkingSchedule;
import com.smart.system.service.IWorkingScheduleService;
import com.smart.common.utils.poi.ExcelUtil;
import com.smart.common.core.page.TableDataInfo;

/**
 * 排班Controller
 * 
 * @author smart
 * @date 2024-09-18
 */
@RestController
@RequestMapping("/system/schedule")
@Api(tags = "排班")
public class WorkingScheduleController extends BaseController
{
    @Autowired
    private IWorkingScheduleService workingScheduleService;

    /**
     * 查询排班列表
     */
    @ApiOperation(value = "查询考勤设置")
    //@PreAuthorize("@ss.hasPermi('system:schedule:list')")
    @GetMapping("/getWorkingSchedule")
    public R<WorkingSchedule> getWorkingSchedule()
    {
        //多租户
        Long deptId = SecurityUtils.getDeptId();
        WorkingSchedule workingSchedules = workingScheduleService.getOne(Wrappers.lambdaQuery(WorkingSchedule.class).eq(WorkingSchedule::getDeptId,deptId).last("limit 1"),false);
        return R.ok(workingSchedules);
    }


    /**
     * 修改排班
     */
    @ApiOperation(value = "修改/新增排班")
    //@PreAuthorize("@ss.hasPermi('system:schedule:edit')")
    @Log(title = "排班", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Boolean> edit(@RequestBody WorkingSchedule workingSchedule)
    {
        //多租户
        Long deptId = SecurityUtils.getDeptId();
        workingSchedule.setDeptId(String.valueOf(deptId));
        return R.ok(workingScheduleService.saveOrUpdate(workingSchedule));
    }
}
